package com.train.springboot.springboottrain.web;

import com.train.springboot.springboottrain.model.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/user")
public class UserController {


    /**
     * 无需用户登录
     * @return
     */
    @RequestMapping(value = "/index")
    public String index(){
        return "INDEX";
    }


    /**
     * 无需用户登录
     * @return
     */
    //不登录也可以访问，用户未登录访问了需要登陆看的请求 会跳转到这里
    @RequestMapping(value = "/page/login")
    public String loginPage(){
        return "Login Page,请登录";
    }

/*

    //用户未登录访问了需要登陆看的请求 会跳转到这里
    @RequestMapping(value = "/error")
    public String error(){
        return "error";
    }
*/



    //用户登陆的请求
    @RequestMapping(value = "/login")
    public String login(HttpServletRequest request){
        User user = new User();
        user.setId(1);
        user.setUsername("lisi");

        request.getSession().setAttribute("user",user);

        return "Logged，登陆成功";
    }

    /**
     * 需要用户是登录状态
     * @return
     */
    //用户登陆后才可以访问
    @RequestMapping(value = "/center")
    public String center(){
        return "User Center";
    }


}
